package com.ziq.baselib.test.hilt

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.ScreenUtils
import com.ziq.base.base.BaseFragment
import com.ziq.base.extension.binding
import com.ziq.baselib.MainActivity
import com.ziq.baselib.MainRecycleViewAdapter
import com.ziq.baselib.R
import com.ziq.baselib.business.post.PostingListActivity
import com.ziq.baselib.business.post.PostingListViewModel
import com.ziq.baselib.databinding.FragmentHiltBinding
import com.ziq.baselib.test.databinding.DataBindingActivity
import com.ziq.baselib.test.drawable.DrawableActivity
import com.ziq.baselib.test.horizontalpage.HorizontalPageActivity
import com.ziq.baselib.test.horizontalpage.HorizontalPageActivity2
import com.ziq.baselib.test.io.IoStreamActivity
import com.ziq.baselib.test.livedata.LiveDataActivity
import com.ziq.baselib.test.toast.ToastActivity
import dagger.hilt.android.AndroidEntryPoint
import java.util.ArrayList

@AndroidEntryPoint
class HiltFragment: BaseFragment(R.layout.fragment_hilt) {

    private val binding : FragmentHiltBinding? by binding()

    val mViewModel: PostingListViewModel by viewModels()
    var dataList: MutableList<MainActivity.DemoListItem> = ArrayList()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return super.onCreateView(inflater, container, savedInstanceState)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding?.root
        mViewModel.onRefresh()
        initData()
        (binding?.recycleView?.layoutParams as? ConstraintLayout.LayoutParams)?.also {
            it.matchConstraintMaxHeight = ScreenUtils.getScreenHeight()
            binding?.recycleView?.layoutParams = it
        }
        binding?.recycleView?.layoutManager = LinearLayoutManager(context)
        binding?.recycleView?.adapter = MainRecycleViewAdapter(context, dataList)
    }

    private fun initData() {
        dataList.add(
            MainActivity.DemoListItem(
                "DEMO-MvvMActivity",
                PostingListActivity::class.java
            )
        )
        dataList.add(
            MainActivity.DemoListItem(
                "DEMO-DataBindingActivity",
                DataBindingActivity::class.java
            )
        )
        dataList.add(MainActivity.DemoListItem("DEMO-HiltActivity", HiltActivity::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-HiltActivity2", HiltActivity2::class.java))
        dataList.add(
            MainActivity.DemoListItem(
                "DEMO-HiltFragment",
                HiltFragmentActivity::class.java
            )
        )
        dataList.add(MainActivity.DemoListItem("DEMO-LiveData", LiveDataActivity::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-Drawable", DrawableActivity::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-IO", IoStreamActivity::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-Toast", ToastActivity::class.java))
        dataList.add(
            MainActivity.DemoListItem(
                "DEMO-HorizontalPage",
                HorizontalPageActivity::class.java
            )
        )
        dataList.add(
            MainActivity.DemoListItem(
                "DEMO-HorizontalPage2",
                HorizontalPageActivity2::class.java
            )
        )
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-1", HorizontalPageActivity2::class.java))
        dataList.add(MainActivity.DemoListItem("DEMO-11", HorizontalPageActivity2::class.java))
    }

}